package com.kcloud.zkem.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import io.swagger.annotations.*;
/**
 * @author guor
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {
    @Bean
    public Docket createAppApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .groupName("应用管理接口")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//                .apis(RequestHandlerSelectors.basePackage("com.kcloud.zkem.web.*"))
                .paths(PathSelectors.any())
                .build()
//                .extensions(Lists.newArrayList(new OrderExtensions(1)))
//                .securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey(),apiKeyBearerToken()))
                ;
    }
//    @Bean
//    public Docket createRouteApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .groupName("路由管理接口")
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.kcloud.ms.authentication.gatewayroute"))
//                .paths(PathSelectors.any())
//                .build().securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey(),apiKey1()));
//    }

    private ApiKey apiKey(){ return  new ApiKey("Basic" ,"Authorization","header");}
    private ApiKey apiKeyBearerToken(){ return  new ApiKey("BearerToken" ,"Authorization","header");}

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("中控考勤机 APIs")
                .description("中控考勤机相关接口")
//                .termsOfServiceUrl("http://localhost:8999/")
                .contact("guorui@goldogv.com")
                .version("1.0")
                .build();
    }
}
